package com.kgc.ljp.BufferStreamDemo;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class BufferedStreamDemo {
    public static void main(String[] args) throws IOException {
        //BufferedInputStream普通写法
        String file = "out.txt";
        InputStream ins = new FileInputStream(file);
        BufferedInputStream bufin= new BufferedInputStream(ins);
        int b;
        while((b=bufin.read())!=-1){
            System.out.println(Integer.toHexString(b));
        }
        //常用写法，只要用到FileInputStream的地方都可以套一个BufferedInputStream用来提升性能
        BufferedInputStream in = new BufferedInputStream(
                new FileInputStream("out.txt"));

        //BufferedOutputStream
        BufferedOutputStream out = new BufferedOutputStream(
                new FileOutputStream("out.txt"));
        out.write(65);
    }
}
